package com.sunlands.qdcy.tongzhuo.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.sunlands.qdcy.tongzhuo.model.UserDiaryZanDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;

import javax.persistence.Id;
import java.util.Date;
import java.util.Objects;

/**
 * @author gaoyanfeng
 * @date 2019/5/2914:21
 */
@Data
@JsonSerialize
@ApiModel(value = "日记点赞信息")
@Builder
public class UserDiaryZanVO {

    @Id
    @ApiModelProperty(value = "点赞id")
    private Long id;

    @ApiModelProperty(value = "日记图片内容，多个逗号分隔")
    private String imgUrls;

    @ApiModelProperty(value = "日记id/评论回复id")
    private Long targetId;

    @ApiModelProperty(value = "日记id")
    private Long rootId;

    @ApiModelProperty(value = "点赞用户id")
    private Long zanUserId;
    @ApiModelProperty(value = "点赞用户id,前端冗余字段")
    private Long userId;

    @ApiModelProperty(value = "被点赞用户id")
    private Long zanedUserId;

    @ApiModelProperty(value = "被点赞的内容")
    private String zanedContent;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "1:日记，2:评论，3:回复")
    private Integer type;

    @ApiModelProperty(value = "点赞用户名")
    private String zanUserName;

    @ApiModelProperty(value = "点赞用户目标名称")
    private String learnTargetName;

    public static UserDiaryZanVO from(UserDiaryZanDO userDiaryZan) {
        return Objects.isNull(userDiaryZan) ? null : UserDiaryZanVO.builder()
                .id(userDiaryZan.getId())
                .targetId(userDiaryZan.getTargetId())
                .zanUserId(userDiaryZan.getZanUserId())
                .userId(userDiaryZan.getZanUserId())
                .zanedUserId(userDiaryZan.getZanedUserId())
                .createTime(userDiaryZan.getCreateTime())
                .type(userDiaryZan.getType())
                .build();
    }
}
